﻿// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : tian_
// Created          : 09-04-2018
//
// Last Modified By : tian_
// Last Modified On : 09-04-2018
// ***********************************************************************
// <copyright file="BmModelManager.cs" company="北京智帆高科科技有限公司">
//     Copyright © 北京智帆高科科技有限公司 2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections.Generic;
using System.Linq;
using OSS.BIM.Business.Utility;
using OSS.BIM.Model;
using OsgEarth;
using OSS.BIM.SceneManage;
using ZFGK.OSG.UI;
using ZFGK.osgEarth.UI;

namespace OSS.BIM.Utility
{
    /// <summary>
    /// Class BmModelManager.
    /// </summary>
    public static class BmModelManager
    {
        /// <summary>
        /// Adds the or replace model.
        /// </summary>
        /// <param name="modelElement">The model information.</param>
        public static void AddOrReplaceModel(this ZfOsgEarthObj osgEarthObj, ModelElement modelElement)
        {
            var modelGrope = modelElement.GetModelGrope();
            osgEarthObj.AddOrReplaceGroup(modelGrope, false);
            osgEarthObj.AddOrReplaceModel(modelElement.ModelGropeId.ToString(), modelElement.GetNode(osgEarthObj.MapNode.getMapSRS()));
        }

        /// <summary>
        /// Adds the or replace model.
        /// </summary>
        /// <param name="modelInfos">The model infos.</param>
        public static void AddOrReplaceModel(this ZfOsgEarthObj osgEarthObj, IList<ModelElement> modelInfos)
        {
            if (modelInfos == null || modelInfos.Count == 0)
                return;

            var modelGrope = modelInfos.First().GetModelGrope();
            osgEarthObj.AddOrReplaceGroup(modelGrope, false);
            osgEarthObj.AddOrReplaceModel(modelGrope.ModelGropeId.ToString(), modelInfos.Select(d => d.GetNode(osgEarthObj.MapNode.getMapSRS())));
        }


        /// <summary>
        /// Deletes the model.
        /// </summary>
        /// <param name="modelElement">The model information.</param>
        public static void DeleteModel(this ZfOsgEarthObj osgEarthObj, ModelElement modelElement)
        {
            osgEarthObj.DeleteModel(modelElement.GetGroupName(), modelElement.ModelElementId.ToString());
        }

        /// <summary>
        /// Deletes the model.
        /// </summary>
        /// <param name="modelInfos">The model infos.</param>
        public static void DeleteModel(this ZfOsgEarthObj osgEarthObj, IList<ModelElement> modelInfos)
        {
            if (modelInfos == null || modelInfos.Count == 0)
                return;

           osgEarthObj.DeleteModel(modelInfos.First().GetGroupName(), modelInfos.Select(d => d.ModelElementId.ToString()).ToArray());
        }

        /// <summary>
        /// Adds the or replace group.
        /// </summary>
        /// <param name="modelGrope">The model grope.</param>
        public static void AddOrReplaceGroup(this ZfOsgEarthObj osgEarthObj, ModelGrope modelGrope)
        {
            var group = modelGrope.GetProject().GetGroup(osgEarthObj.MapNode.getMapSRS());
            group.Name = modelGrope.ModelGropeId.ToString();
            osgEarthObj.AddOrReplaceGroup(group);
        }

        /// <summary>
        /// Adds the or replace group.
        /// </summary>
        /// <param name="modelGrope">The model grope.</param>
        /// <param name="replace">if set to <c>true</c> [replace].</param>
        public static void AddOrReplaceGroup(this ZfOsgEarthObj osgEarthObj, ModelGrope modelGrope, bool replace)
        {
            var group = modelGrope.GetProject().GetGroup(osgEarthObj.MapNode.getMapSRS());
            group.Name = modelGrope.ModelGropeId.ToString();
            osgEarthObj.AddOrReplaceGroup(group);
        }

        public static Dictionary<long, ElevationLayer> ElevationLayerMap = new Dictionary<long, ElevationLayer>();
    }
}
